 <?php
/**
 * Handles the view functionality of our MVC framework
 */
class Core_Model_View
{
    /**
     * Holds variables assigned to template
     */
    private $data = array();

    /**
     * Holds render status of view.
     */
    private $render = FALSE;

    /**
     * Accept a template to load
     */
    public function __construct($template)
    {
        
    	try {
        	if (file_exists($template))
        	{
            	/**
             	* trigger render to include file when this model is destroyed
             	* if we render it now, we wouldn't be able to assign variables
             	* to the view!
             	*/
            	$this->render = $template;
        	}
        	else {
        		throw new Exception("File '$tempate' does not exists!");
        	}
    	}
    	catch(Exception $e){
    		echo $e->getMessage();
    	}
    }

    /**
     * Receives assignments from controller and stores in local data array
     * 
     * @param $variable
     * @param $value
     */
    public function assign($variable , $value)
    {
        $this->data[$variable] = $value;
    }

    public function __destruct()
    {
        //parse data variables into local variables, so that they render to the view
        $data = $this->data;
    	
        //render view
        include($this->render);
    }
} 